VBA: Selecting only rows with data in a range

forrad

New Member
Joined
Jan 22, 2014
Messages
5
Hello all,

I am working on a spreadsheet, in which I have written a macro whereby it selects and cuts data within a defined range (in this case "K1:T1001") and pastes this to the first empty row in column A. Here is the specific line used in this macro:

If Not IsEmpty(MyCell) Then
ActiveSheet.Range("K1:T1001").Cut Destination:=ActiveSheet.Range("A" & Rows.Count).End(xlUp).Offset(2)
End If

I would like to use this macro for other similar spreadsheets where the range of rows to be selected may differ (however, the columns will always be K:T). I'm afraid I have reached my limit of knowledge with VBA to know how to select only cells containing data within this range.

Any help would be greatly appreciated!

:)
 
Code:
Do While Application.WorksheetFunction.CountA(Range("K:T")) > 0
    LastRow = Cells(Rows.Count, "R").End(x1Up).Row 
    ActiveSheet.Range("K1:T"&LastRow).Cut Destination:=ActiveSheet.Range("A" & Rows.Count).End(xlUp).Offset(2)
    Range("K:T").EntireColumn.Delete
Loop
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,215,223
Messages
6,123,715
Members
449,118
Latest member
MichealRed

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