I am trying to reconfigure this instead of going through all the rows within a column to just use the active cells row.
Currently, the routine will look though Column C 13 down, It will find the last value within Column C and then string the C Cell and the Next cell to the right (If a value is there) and string them together.
I hope this kind of makes some sense.
Ultimately I would like to Select a Cell Value in Column C and then have it string the Cell Value in D, finally, Send that value to the CAD Command.
Basically taking the below and modifying it to follow the above statement somehow lol.
Full Routine
Thank you for any help guys!
Currently, the routine will look though Column C 13 down, It will find the last value within Column C and then string the C Cell and the Next cell to the right (If a value is there) and string them together.
I hope this kind of makes some sense.
Ultimately I would like to Select a Cell Value in Column C and then have it string the Cell Value in D, finally, Send that value to the CAD Command.
Basically taking the below and modifying it to follow the above statement somehow lol.
VBA Code:
'Loop through all the rows of the sheet that contain commands.
For i = 13 To LastRow
'Find the last column.
LastColumn = .Cells(i, .Columns.Count).End(xlToLeft).Column
'Check if there is at least on command in each row.
If LastColumn > 2 Then
'Create a string that incorporates all the commands that exist in each row.
acadCmd = ""
For j = 3 To LastColumn
If Not IsEmpty(.Cells(i, j).Value) Then
acadCmd = acadCmd & .Cells(i, j).Value & vbCr
End If
Next j
'Send Command to AutoCAD.
If Val(acadApp.Version) < 20 Then
Else
acadDoc.SendCommand acadCmd & vbCr
End If
End If
Sleep 20
Next i
Send AutoCAD Commands From Excel & VBA CLEANEDUP.xlsm | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
12 | No. | Command | Argument 1 | |||
13 | 1 | z2s | 05 | |||
14 | 2 | |||||
15 | 3 | |||||
16 | 4 | |||||
17 | 5 | |||||
18 | 6 | |||||
19 | 7 | |||||
20 | 8 | |||||
21 | 9 | |||||
22 | 10 | |||||
23 | 11 | |||||
24 | 12 | |||||
25 | 13 | |||||
26 | 14 | |||||
27 | 15 | |||||
Sheet1 |
Full Routine
VBA Code:
Option Explicit
'Declaring the API Sleep subroutine.
#If VBA7 And Win64 Then
'For 64 bit Excel.
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
'For 32 bit Excel.
'Public Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
#End If
Sub SendCommands()
Dim acadApp As Object
Dim acadDoc As Object
Dim acadCmd As String
Dim sht As Worksheet
Dim LastRow As Long
Dim LastColumn As Integer
Dim i As Long
Dim j As Integer
Set sht = ThisWorkbook.Sheets("Sheet1")
'Activate the Send AutoCAD Commands sheet and find the last row.
With sht
.Activate
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
'<<<----- How could I get this to be the Active Column and Cell?
End With
On Error Resume Next
Set acadApp = GetObject(, "AutoCAD.Application")
If acadApp Is Nothing Then
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True
End If
On Error Resume Next
Set acadDoc = acadApp.ActiveDocument
If acadDoc Is Nothing Then
Set acadDoc = acadApp.Documents.Add
End If
On Error GoTo 0
With sht
'Loop through all the rows of the sheet that contain commands.
For i = 13 To LastRow
'Find the last column.
LastColumn = .Cells(i, .Columns.Count).End(xlToLeft).Column
'Check if there is at least on command in each row.
If LastColumn > 2 Then
'Create a string that incorporates all the commands that exist in each row.
acadCmd = ""
For j = 3 To LastColumn
If Not IsEmpty(.Cells(i, j).Value) Then
acadCmd = acadCmd & .Cells(i, j).Value & vbCr
End If
Next j
'Send Command to AutoCAD.
If Val(acadApp.Version) < 20 Then
Else
acadDoc.SendCommand acadCmd & vbCr
End If
End If
Sleep 20
Next i
End With
End Sub
Thank you for any help guys!