HELP: VBA to find first non-blank cell in the row?

Urner

New Member
Joined
Sep 3, 2011
Messages
10
How should I write a vba code that will find the first non-blank cell in a specified row range and then copy it to another sheet?



Any suggestions?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Maybe something like this?

Code:
Sub FindFirstNonEmptyCell()
Dim i, j As Integer 'i = row number, j = collumn number
    For i = 1 To 2 'replace '1 and 2' to the desires range
        For j = 1 To 256 'or 16384 in Excel2007
            If Not IsEmpty(Cells(i, j)) Then
                Cells(i, j).Copy Sheets(2).Cells(i, 1) 'the first value will be copied to sheet 2
                Exit For
            End If
        Next
    Next
End Sub

Grtz,
Ron
 
Upvote 0
Hi, Just select the first cell in your row range and then run this macro

Code:
Sub Macro2()
    Selection.End(xlToRight).Select
    Selection.Copy
    Sheets("Sheet1").Select  ' Replace "sheet1" with the sheet you want to copy to
    Range("A1").Select       ' Replace A1 with the cell you want to copy to
    ActiveSheet.Paste
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,240
Members
452,898
Latest member
Capolavoro009

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