sanantonio
Board Regular
- Joined
- Oct 26, 2021
- Messages
- 124
- Office Version
- 365
- Platform
- Windows
Hi All,
I suck at loops. I can never get them to work. Ive been sat trying to recycle someone's loop for a couple hours and I can't get it to work
SO,
I need it to loop a Sendkey macro.
I work for a distributor, we have a system that requires the manual keying in of orders by a Human reading from a spreadsheet. Efficiency wise this is of course awful. I'm trying to automate this process.
I'm trying to get the loops to work with the data in the format that it comes to us, but if there's a recommendation that makes everything work but the data needs to be presented in a different format that can be arranged.
My macro needs to take this data and put it into this antiquated module:
Currently my code looks like:
(I've inserted comments using the ')
There's a lot of redundant code in there, because like I say I'm trying to retrofit another macro.
Is this double loop process possible? Where it'll loop thru store/order area/supplier/date, then loop through items, then jump to the next store/order area/supplier/date, then loop through items, then jump to the next store/order area/supplier/date etc. ?
Anyone able to help me out?
I suck at loops. I can never get them to work. Ive been sat trying to recycle someone's loop for a couple hours and I can't get it to work
SO,
I need it to loop a Sendkey macro.
I work for a distributor, we have a system that requires the manual keying in of orders by a Human reading from a spreadsheet. Efficiency wise this is of course awful. I'm trying to automate this process.
I'm trying to get the loops to work with the data in the format that it comes to us, but if there's a recommendation that makes everything work but the data needs to be presented in a different format that can be arranged.
My macro needs to take this data and put it into this antiquated module:
Currently my code looks like:
(I've inserted comments using the ')
VBA Code:
Sub testing2()
Dim myAlo As Range
Dim myRow, myCount As Long
Dim myWindow As String
Dim myItem, myQuantity As Range
Dim mySlot As Variant
Dim hWnd As Long
Dim Row1 As Long, Row2 As Long, Num1 As Long, Counter1 As Long
Dim Item As Range, Items As Range
Dim ItemCode As String
Dim Window1 As String, Window2 As String, Window3 As String
'Select MDE Module
Window1 = "[MDE000] - MDE Module - DB: USWH00" & Sheets("Cover").Range("J13").Value & "L (USWH00" & Sheets("Cover").Range("J13").Value & "L) Schema: WAWIADM Role: R_WAWI"
Window2 = "[MDE007] Manual Picklist"
hWnd = FindWindow(vbNullString, Window1)
SetForegroundWindow hWnd
If hWnd > 0 Then
Else
MsgBox ("MDE Module cannot be found.")
myCancel = "Cancel"
Exit Sub
End If
'Loop 1, enters store, order area, date, and supplier
'Currently as you can see in the screenshot above are separated by words, if a different format is necessary please recommend! I can easily build something that reformats.
'Store
SendKeys ActiveSheet.Range("L4").Value
SendKeys ("{TAB}")
'Order Area
SendKeys ActiveSheet.Range("L6").Value
SendKeys ("{TAB}")
'Date
SendKeys ActiveSheet.Range("L7").Value
SendKeys ("{TAB}")
'Supplier
SendKeys ActiveSheet.Range("L5").Value
SendKeys ("{TAB}")
'Loop 2, Then loops through items and quanities
'Items - Currently this just runs for the first 2 items. The sendkeys need 2 happen after each item / quantity is entered but the cell reference needs 2 loop
SendKeys ActiveSheet.Range("K9").Value 'First item code
SendKeys ("{TAB}")
SendKeys ("{TAB}")
SendKeys ActiveSheet.Range("L9").Value 'First item quantity
SendKeys ("{TAB}")
SendKeys (" ")
SendKeys ActiveSheet.Range("K10").Value 'Second item code
SendKeys ("{TAB}")
SendKeys ("{TAB}")
SendKeys ActiveSheet.Range("L10").Value 'Second item quantity
SendKeys ("{TAB}")
SendKeys (" ")
'Saves once all items are complete END OF LOOP 2
SendKeys ("{F3}")
'<> Starts next Store/Supplier/OrderArea/Date
'Back in2 Loop 2.
End Sub
There's a lot of redundant code in there, because like I say I'm trying to retrofit another macro.
Is this double loop process possible? Where it'll loop thru store/order area/supplier/date, then loop through items, then jump to the next store/order area/supplier/date, then loop through items, then jump to the next store/order area/supplier/date etc. ?
Anyone able to help me out?