585,875 active members*
3,933 visitors online*
Register for free
Login
IndustryArena Forum > Machine Controllers Software and Solutions > G-Code Programing > Any Excel/VBA Experts out there to help me with an Excel G-Code Macro?
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2008
    Posts
    139

    Any Excel/VBA Experts out there to help me with an Excel G-Code Macro?

    I'll be blunt - I'm crap at programming....I've kludged a spreadsheet together which produces G-Code...but I want a Macro to run on this spreadsheet to extract some of the fields and assemble them automatically into G-Code lines - I'm almost there, but stuck with this little stumbling block (you must promise not to laugh as you see how I've done this!).

    I'm using the value of a number located in my spreadsheet cell (cell B16), to generate a number of Excel rows (which ultimately will contain CNC winder code when the Excel Macro is run)...

    Code:
    For counter = 1 To Range("B16")
    Set CurCell = Worksheets("Sheet1").Cells(counter + 36, 1)
    CurCell.Value = "G01"
    Next counter
    
    For counter = 1 To Range("B16")
    Set CurCell = Worksheets("Sheet1").Cells(counter + 36, 2)
    CurCell.Value = "X"
    Next counter
    
    For counter = 1 To Range("B16")
    Set CurCell = Worksheets("Sheet1").Cells(counter + 36, 3)
    CurCell.Value = Range("B10").Value
    Next counter
    
    For counter = 1 To Range("B16")
    Set CurCell = Worksheets("Sheet1").Cells(counter + 36, 4)
    CurCell.Value = "Y"
    Next counter
    
    For counter = 1 To Range("B16")
    Set CurCell = Worksheets("Sheet1").Cells(counter + 36, 5)
    CurCell.Value = Range("B13").Value * counter
    Next counter
    
    For counter = 1 To Range("B16")
    Set CurCell = Worksheets("Sheet1").Cells(counter + 36, 6)
    CurCell.Value = "F"
    Next counter
    
    For counter = 1 To Range("B16")
    Set CurCell = Worksheets("Sheet1").Cells(counter + 36, 7)
    CurCell.Value = Range("B5").Value
    Next counter
    So if there's the number 10 in the spreadsheet's cell "B16", presently I end up with 10 rows looking something like this (sorry about the G-Code formatting)....

    G01 X 4.2371 Y 15.11677444 F 40
    G01 X 4.2371 Y 30.23354888 F 40
    G01 X 4.2371 Y 45.35032332 F 40
    G01 X 4.2371 Y 60.46709776 F 40
    G01 X 4.2371 Y 75.58387219 F 40
    G01 X 4.2371 Y 90.70064663 F 40
    G01 X 4.2371 Y 105.8174211 F 40
    G01 X 4.2371 Y 120.9341955 F 40
    G01 X 4.2371 Y 136.05097 F 40
    G01 X 4.2371 Y 151.1677444 F 40

    You can see that the X position remains constant - this is not what I want, read on....

    I've bolded a blue section in the VBA code above, I really need that part of the VBA code to output an X coord number one line from the number sourced from cell B9 & the next G-Code line to have a X Coord sourced from cell B10...and alternate until the number of G-Code rows are finished. So for example, I'd like the output from the above code to look like this instead of the above

    G01 X 4.2371 Y 15.11677444 F 40
    G01 X 0.263 Y 30.23354888 F 40
    G01 X 4.2371 Y 45.35032332 F 40
    G01 X 0.263 Y 60.46709776 F 40
    G01 X 4.2371 Y 75.58387219 F 40
    G01 X 0.263 Y 90.70064663 F 40
    G01 X 4.2371 Y 105.8174211 F 40
    G01 X 0.263 Y 120.9341955 F 40
    G01 X 4.2371 Y 136.05097 F 40
    G01 X 0.263 Y 151.1677444 F 40

    (where the X coor number 0.263 is sourced from cell "B9" & the other X Coord number 4.2371 is sourced from cell "B10")

    Could some kind soul give me a pointer as to how I can approach this last bit of my quest?!

  2. #2
    Join Date
    Mar 2003
    Posts
    35538
    How about this?

    For counter = 1 To Range("B16") step 2
    Set CurCell = Worksheets("Sheet1").Cells(counter + 36, 3)
    CurCell.Value = Range("B10").Value
    Next counter

    For counter = 2 To Range("B16") step 2
    Set CurCell = Worksheets("Sheet1").Cells(counter + 36, 3)
    CurCell.Value = Range("B9").Value
    Next counter
    Gerry

    UCCNC 2017 Screenset
    http://www.thecncwoodworker.com/2017.html

    Mach3 2010 Screenset
    http://www.thecncwoodworker.com/2010.html

    JointCAM - CNC Dovetails & Box Joints
    http://www.g-forcecnc.com/jointcam.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  3. #3
    Join Date
    Jul 2008
    Posts
    139
    Wow Gerry ...that works a treat :banana: - many thanks, I'd have never come up with that one! (well, not this side of Xmas anyway!)

    Great stuff ...thanks once again :cheers:

  4. #4
    Join Date
    Jun 2009
    Posts
    10
    Can you explain to me, how to produce gcode from spreadsheet?

Similar Threads

  1. Replies: 19
    Last Post: 11-07-2019, 08:16 PM
  2. 4 Axis CNC - MS Excel Source code (VBA)
    By arman in forum Visual Basic
    Replies: 3
    Last Post: 03-06-2018, 01:37 AM
  3. macro in excel
    By mike9696 in forum Parametric Programing
    Replies: 4
    Last Post: 08-28-2009, 11:44 PM
  4. need help with excel vba macro
    By Timbersmith in forum G-Code Programing
    Replies: 7
    Last Post: 05-08-2008, 01:46 AM
  5. new post processor or excel macro or...
    By trubble2rubble in forum G-Code Programing
    Replies: 3
    Last Post: 07-16-2005, 02:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •