putting value in first nonempty column using VBA

yummy

Board Regular
Joined
Jan 18, 2011
Messages
63
Is it possible to check a column e.g. column H starting from H2 and put a value (lets say "I found it") in the first nonempty cell found in this column using VBA?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi yummy,

Are you sure you mean nonempty in that you want to over-write the first entry (nonempty) row in Column H starting at Row 2 or do you mean put the text into the the first blank (null) cell?

Robert
 
Upvote 0
Sorry for the confusion. My bad
I want to put the text in first empty(blank) cell found in column H starting from range H2.
Dont wanna overwrite

THx for the reply.
 
Upvote 0
No problem, try this:

Code:
Sub Macro1()
    
    Dim lngRowEnd As Long
    Dim rngCell As Range, _
        rngMyDataSet As Range
    
    lngRowEnd = Cells(Rows.Count, "H").End(xlUp).Row
    Set rngMyDataSet = Range("H2:H" & lngRowEnd)
    
    Application.ScreenUpdating = False
    
    For Each rngCell In rngMyDataSet
    
        If Len(rngCell.Value) = 0 Then
        
            rngCell.Value = "I found it"
        
            Exit For
            
        End If
        
    Next rngCell
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
Hey Yummy,
Maybe you'd also like to try
Code:
Sub trythis()
Dim stg As String, e As Range
stg = "I found it"
Set e = Range("H2")
If e(2) = vbNullString Then e(2) = stg Else e.End(4)(2) = stg
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top