how to make this less in proper code

wndncg

Board Regular
Joined
Mar 24, 2017
Messages
82
Office Version
  1. 2019
  2. 2016
  3. 2013
Sub INSERT_ME3()
Worksheets("1").Activate
Application.Wait (Now + TimeValue("0:00:01"))
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A6").Select
Range("A6").Value = Worksheets("1").Range("L5")
Application.Wait (Now + TimeValue("0:00:01"))
Range("B6").Select
Application.Wait (Now + TimeValue("0:00:01"))
Application.SendKeys ("^+{DOWN}")
Application.Wait (Now + TimeValue("0:00:01"))
Application.SendKeys ("^{DOWN}")
Application.SendKeys ("{LEFT}")
Application.SendKeys ("^{DOWN}")
Application.SendKeys ("+{SPACE}")
End Sub

---
see video how it works (doesnt work atm because i need help)
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
May I suggest that you explain what you need to do, rather then ask us to decode the video?
 
Upvote 0
May I suggest that you explain what you need to do, rather then ask us to decode the video?
sequence:

1. Selector goes to b6 then shift down (to the last data highlighted)
2. Selector goes to the left side (from the last data highlighted as seen on the video)
3. Selector shift up (to the last data highlighted, purpose is to get into the last data available as seen on the video)
4. Then fills up the entire blank cells with the data on A6 (A6 is just an example to populate the data but the purpose is that, it fills the blank data is on what from the shift up on step 3)
5. Then it shift space (purpose is to highlight all of it, as seen on the video)
 
Upvote 0
After minutes of headaches, my best translation of what you wrote is:
-working on sheet named "1"
-I have data in column B up to line XX (unknown)
-and I would like in column A to copy the last data available there up to line XX

If that is correct then try
VBA Code:
Sub boh()
Dim LastB As Long, LastA As Long
'
Worksheets("1").Select
LastB = Cells(Rows.Count, "B").End(xlUp).Row
LastA = Cells(LastB, "A").End(xlUp).Row
If LastA < LastB Then
    Range(Cells(LastA, "A"), Cells(LastB, "A")).FillDown
End If
End Sub
 
Upvote 0
There is almost never a need to use .Select/.Activate. You can perform most of the operation without using them by directly working with the objects.

I think this is what you are trying to do after watching the video. (The video link is blocked in my country so had to use vpn to see it.)

I have commented the code so you should not have an issue understanding it. But if you do, then simply ask.

VBA Code:
Option Explicit

Sub INSERT_ME3()
    Dim ws As Worksheet
    Dim lRow As Long
    
    '~~> This is your worksheet object
    Set ws = ThisWorkbook.Worksheets("1")

    With ws
        '~~> Insert column
        .Columns(1).Insert Shift:=xlToRight
        
        '~~> Directly assign the value without selecting it
        .Range("A6").Value = .Range("L5").Value
        
        '~~> Find last row in Col B
        lRow = .Range("B" & .Rows.Count).End(xlUp).Row
        
        '~~> Autofill the data of cell A6 in rest of blank cells
        .Range("A6:A" & lRow).Value = .Range("A6").Value
    End With
End Sub
 
Upvote 0
After minutes of headaches, my best translation of what you wrote is:
-working on sheet named "1"
-I have data in column B up to line XX (unknown)
-and I would like in column A to copy the last data available there up to line XX

If that is correct then try
VBA Code:
Sub boh()
Dim LastB As Long, LastA As Long
'
Worksheets("1").Select
LastB = Cells(Rows.Count, "B").End(xlUp).Row
LastA = Cells(LastB, "A").End(xlUp).Row
If LastA < LastB Then
    Range(Cells(LastA, "A"), Cells(LastB, "A")).FillDown
End If
End Sub
this works but i does not highlight all cells.
 
Upvote 0
Then add one extra Instruction:
VBA Code:
If LastA < LastB Then
    Range(Cells(LastA, "A"), Cells(LastB, "A")).FillDown
    Range(Cells(LastA, "A"), Cells(LastB, "B")).Select              '<<< ADD THIS LINE
End If
 
Upvote 0
Then add one extra Instruction:
VBA Code:
If LastA < LastB Then
    Range(Cells(LastA, "A"), Cells(LastB, "A")).FillDown
    Range(Cells(LastA, "A"), Cells(LastB, "B")).Select              '<<< ADD THIS LINE
End If
like the whole cell from a to the last >>>>>>>>>>>>>>>>> cell
 
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,869
Members
449,192
Latest member
MoonDancer

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