Auto select?

sandwhich

New Member
Joined
Mar 14, 2013
Messages
12
Hello All!

Is it possible to create a rule or VBA that says, if the data is column A is not 0 then select that entire row, or all the data in that row? So, in the below scenario when I paste the following data in the spreadsheet, it would automatically select the row, or all the data in the rows with 123 and 789? Or is there an easier what to do that without manually selecting the rows? I'm not sure if I am asking this correctly.

1230AAA
00BBB
00CCC
7890DDD
00EEE

<tbody>
</tbody>
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
.
Presuming your data above begins in A2, this macro will copy rows not beginning with 0, to Sheet 2.

Code:
Option Explicit
Sub CopyRowsAcross()
Dim i As Integer
Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("Sheet1")
Dim ws2 As Worksheet: Set ws2 = ThisWorkbook.Sheets("Sheet2")


For i = 2 To ws1.Range("A65536").End(xlUp).Row
    If ws1.Cells(i, 1) <> "0" Then ws1.Rows(i).Copy ws2.Rows(ws2.Cells(ws2.Rows.Count, 1).End(xlUp).Row + 1)
Next i
End Sub
 
Upvote 0
Got it, thank you so much! One last question... what do I change to have it read from A1, instead of A2?
 
Upvote 0
Here is another macro that you can try...
Code:
[table="width: 500"]
[tr]
	[td]Sub SelectRowsIfNotZeroInColumnA()
  Dim LastRow As Long, UnusedCol As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  UnusedCol = Cells.Find("*", , xlFormulas, , xlByColumns, xlPrevious).Column + 1
  Cells(1, UnusedCol).Resize(LastRow) = Evaluate("IF(A1:A" & LastRow & "<>0,1,"""")")
  Columns(UnusedCol).SpecialCells(xlConstants).EntireRow.Select
  Columns(UnusedCol).Clear
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
.
Change the 2 to a 1 on the sixth line down:

Code:
Option Explicit
Sub CopyRowsAcross()
Dim i As Integer
Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("Sheet1")
Dim ws2 As Worksheet: Set ws2 = ThisWorkbook.Sheets("Sheet2")




For i = 1 To ws1.Range("A65536").End(xlUp).Row
    If ws1.Cells(i, 1) <> "0" Then ws1.Rows(i).Copy ws2.Rows(ws2.Cells(ws2.Rows.Count, 1).End(xlUp).Row + 1)
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,558
Latest member
aivin

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