PDA

View Full Version : [SOLVED:] VBA find the FIRST real row



QuaDen
05-03-2016, 06:22 PM
Need alot of help
what's wrong with my code???? i need it to cut one by one A2, A3, A4, .... and paste to A1 :(
im still new to VBA and no one in my office seems to be able to have the time to help me :banghead:u

-----------------------------------------------------------

Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+g
'
Range("A2").Select
Selection.Cut
Range("A1").Select
ActiveSheet.Paste


Sub FindNextRow()

Dim LastRow As Long
Dim LastCol As Long

' Find the FIRST real row
LastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row

' Find the LAST real column
LastCol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlNext, _
SearchOrder:=xlByColumns).Column

'Select the ACTUAL Used Range as identified by the
'variables identified above
ActiveSheet.Cells(LastRow - 1, 1).Select



End Sub

Paul_Hossler
05-03-2016, 06:49 PM
1. Are you missing an 'End Sub'?

2. You said Find First real row, but variables are LastRow and LastCOl

3. "i need it to cut one by one A2, A3, A4, .... and paste to A1" -- not sure what this means

4. Can you attach a small workbook showing what you have and what you want?





Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+g
'
Range("A2").Select
Selection.Cut
Range("A1").Select
ActiveSheet.Paste
End Sub ' <<----------------------------------------------------------

Sub FindNextRow()

Dim LastRow As Long
Dim LastCol As Long

' Find the FIRST real row
LastRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row

' Find the LAST real column
LastCol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlNext, _
SearchOrder:=xlByColumns).Column

'Select the ACTUAL Used Range as identified by the
'variables identified above
ActiveSheet.Cells(LastRow - 1, 1).Select



End Sub

QuaDen
05-03-2016, 06:55 PM
Hi Paul

This is my workbook

QuaDen
05-03-2016, 08:44 PM
I'm test this code but it's not work:



' Find the FIRST real row
FirstRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlNext, _
SearchOrder:=xlByRows).Row

' Find the FIRST real column
FirstCol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlNext, _
SearchOrder:=xlByColumns).Column

gmayor
05-04-2016, 12:02 AM
Even with the worksheet it is difficult to understand the aim of the process.
However, based on your original post I think the following may be what you require.


Range("A1").Delete Shift:=xlUp

QuaDen
05-04-2016, 12:11 AM
Even with the worksheet it is difficult to understand the aim of the process.
However, based on your original post I think the following may be what you require.


Range("A1").Delete Shift:=xlUp

wow, thank gmayor so much, that's my repuire