If you are a true believer in the Lord Jesus Christ, the Holy Spirit was given to you the moment you believed and He will never leave you. This is confirmed in the following scriptures:

“And I will pray the Father, and He will give you another Helper, that He may ABIDE WITH YOU FOREVER—the Spirit of truth, whom the world cannot receive, because it neither sees Him nor knows Him; but you know Him, for He dwells with you and will be in you….In Him (the Lord Jesus) you also trusted, after you heard the word of truth, the gospel of your salvation; in whom also, having believed, you were SEALED WITH THE HOLY SPIRIT of promise” (John 14:16 and Ephesians 1:13…NKJV).

These verses assure the believer that the Holy Spirit “abides with you forever.” He has SEALED us, which means He has “marked us out as those who belong to Christ” and “guarantees that we will never lose our salvation.” Yet there is a serious consequence when we sin, for when we sin we GRIEVE the Holy Spirit. The Apostle Paul had warned the saints at Ephesus about sinning with our tongue and then he said, “And do not grieve the Holy Spirit of God, by whom you were sealed for the day of redemption” (Ephesians 4:30). The Holy Spirit is a Divine Person Who has feelings and the moment we sin we cause Him grief. When this happens He is no longer free to carry on His mission in us, which is to present Christ to us through the scriptures and to empower us to testify of Christ to a lost world (see John 16:13-14 and 15:26-27). Instead, He will have to convict us of our sin and bring us to confess our sin in true repentance in order to restore us to fellowship with the Father and the Son. “If we confess our sins, He is faithful and just to forgive us our sins and to cleanse us from all unrighteousness.” Once we are restored to fellowship the Holy Spirit is no longer grieved and He can continue His blessed work of “guiding us into all truth” and “taking the things of Christ and declaring them unto us” (again, see John 16:13-14).

I should mention that BEFORE Jesus Christ finished the work of atonement on the cross believers did NOT have the Holy Spirit indwelling them. He was “WITH believers,” but He was not “IN believers.” We had already seen this in John 14:16 when Jesus said, “….He dwells with you and will be in you.” Because the Holy Spirit did not indwell them He could indeed leave them if they sinned. Perhaps most of us are familiar with David’s prayer of repentance recorded in Psalm 51 where he was made to cry out, “Do not cast me away from Your presence, and do not take Your Holy Spirit from me.” I have actually heard believers pray that very same prayer today, yet they do so in ignorance, for once we see that the Holy Spirit has “sealed us for the day of redemption” (Ephesians 4:30) we will never be found praying for the Holy Spirit to NOT to leave us, or for the Holy Spirit to come back to us. (328.5) (DO)