Decipher & possibly change an inherited macro

sanantonio

Board Regular
Joined
Oct 26, 2021
Messages
124
Office Version
  1. 365
Platform
  1. Windows
Hi All,

Have inherited the following macro. It basically loops through a list of numbers and sendkeys them all into a computer-specific data input screen.

1684332534717.png


Could anyone please help me with a translation? I've added my own where I can determine what's what.

VBA Code:
Sub ALO_SendKeys()

Dim i As Long
Dim U As Long

For i = ActiveCell.Row To Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row
'Minimizes excel window
       Application.WindowState = xlMinimized 
       
'If blank return 0
 If Cells(i, ActiveCell.Column) = "" Then
    Application.SendKeys ("0")
      Else
      End If
       
       Application.SendKeys Cells(i, ActiveCell.Column), True
       Application.SendKeys "{DOWN}"


Next i

    Application.SendKeys "{NUMLOCK}"

End Sub

Not really sure how it works, I presume somewhere in there we're telling it to input what is in the cell, then the next etc.

It seems to only work when you have the correct cell highlighted to begin with. I presume this is dictated by this line of code:

VBA Code:
For i = ActiveCell.Row To Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row

Could someone help me out with the correct code for making this work regardless of what cell you have highlighted if the numbers always begin in D7 ?

Thanks y'all!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
To have it go from D7 down to the last row with data in column D, you can change that line to this:
VBA Code:
For i = 7 To Cells(Rows.Count, "D").End(xlUp).Row
 
Upvote 0
Solution
Hi, thanks for coming back to me so quickly!

That worked to mean it only copied from Row 7 but ignored the D completely.

I managed to fix this by running a Range("D7").Select in:

VBA Code:
Sub FVM_Sender()

'Request the user to confirm they've checked everything is on status 9
Dim answer As Integer
answer = MsgBox("Have you checked all your items are in the same order as they appear in FVM?", vbQuestion + vbYesNo)

  If answer = vbYes Then

Dim i As Long
Dim U As Long

Range("D7").Select

For i = 7 To Cells(Rows.Count, "D").End(xlUp).Row
       Application.WindowState = xlMinimized
       
 If Cells(i, ActiveCell.Column) = "" Then
    Application.SendKeys ("0")
      Else
      End If
       
       Application.SendKeys Cells(i, ActiveCell.Column), True
       Application.SendKeys "{DOWN}"

Next i

    Application.SendKeys "{NUMLOCK}"

ActiveWindow.WindowState = xlMaximized

Else
    MsgBox "Please check that all of your items are in the correct order and try again"
  End If

End Sub

And it now works a treat!
 
Upvote 0
That worked to mean it only copied from Row 7 but ignored the D completely.

I managed to fix this by running a Range("D7").Select in:
That is not necessary. You just need to also replace all instances of:
VBA Code:
ActiveCell.Column
with
VBA Code:
"D"

So just update these two references:
VBA Code:
Cells(i, ActiveCell.Column)
to this:
VBA Code:
Cells(i, "D")
and you can get rid of that select statement.
 
Upvote 0
I updated the solution to my original reply.
While they both helped you solved your issue, the first one was geared more towards your original question. So that is probably the one that best answers the original qustion.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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