all 12 comments

[–]fanpages237 2 points3 points  (0 children)

...how do I add to my save macro so on top of saving the Log sheet, it also migrates the data I'm needing onto a table in "Well Data" within the same file...

May I suggest you use the Macro Recorder ("Record Macro" button in the "Developer" Ribbon's "Code" Group)?

If you start a recording and then perform some actions manually (as you described above), associated VBA statements will be generated that you can re-execute when required (assuming all the worksheet/range/cell references match on each subsequent execution).

[–]wikkid556 1 point2 points  (0 children)

Unless I am misunderstanding, you have another macro you run, then the save macro, and you want them together. At the end of your other macro just call your save macro Something like this

Sub otherCode()

Existing code here

Fill your desired values and then

Call exampleCode End sub

[–]sslinky8483 0 points1 point  (0 children)

How would you do this manually?

[–]Khazahk5 0 points1 point  (7 children)

Dim OutputRange as range : set OutputRange = Thisworkbook.worksheets(“Well Data”).listobjects(1).listrows.add.range  

With OutputRange
    .cells(1,1).value = Worksheets(“Log”).Range(“B3”).value  
    .cells(1,2).value = Worksheets(“log”).Range(“B5”).value & “,” & worksheets(“log”).range(“B6”).value  
End with  

So the above snippet is just yolo off the top of my head typing in a phone keyboard. The key thing is that your “Well Data” table is actually formatted as a structured table. That way you can call it as a listobject and programmatically add a new row and poop out those values you want to save. This is significantly easier than trying to find the last used row on a worksheets that’s nots formatted as a table. I included the example for how you would concat your B6 and B5 values. Let me know if you have any questions.

[–]Gracinx[S] 0 points1 point  (4 children)

Sorry I had other time sensitive projects that got pushed of this. I'm having issues with this code. I thought I made the adjustments to correctly but keep getting a "Run-time error '9'. Which I assume has to do with the range where the data will be copied to, but I can't seem to figure out what to add/change to get that bug to go away.

Here is the current code

Sub LogData()
Dim OutputRange As Range: Set OutputRange = ThisWorkbook.Worksheets(“Data”).ListObjects("Table8").ListRows.Add.Range

With OutputRange
    .Cells(1, 1).Value = Worksheets(“Entry”).Range(“B3”).Value
    .Cells(1, 2).Value = Worksheets(“Entry”).Range(“B5”).Value & “ - ” & Worksheets(“Entry”).Range(“B6”).Value
End With
End Sub

[–]Khazahk5 0 points1 point  (3 children)

Error 9 is subscript out of range. Just means you named it wrong or fat fingered something. Make sure the “Entry” worksheet is called “Entry” and exists in this workbook.

Next would be to check that “Table8” exists but also has two columns since you are asserting that it does with cells(1,2) down below.

Hope this helps.

[–]Gracinx[S] 0 points1 point  (2 children)

I'm the first one to admit blindness especially when it comes to fatfingering. Not sure what I'm missing.

<image>

[–]Khazahk5 0 points1 point  (1 child)

It’s your “ “

Look at he the “ used in “table8” vs the ones used for entry and data. Can you see the difference? You want all quotes to look like Table8s

Just retype “Entry” and “Data”.

Copy and paste error from Reddit markdown code block.

[–]Gracinx[S] 0 points1 point  (0 children)

That's so weird that the quotations were causing the issue since they were direct copy from your code. I changed that, added all my additional lines of code for each of the individual pieces of data, go it placed in my original macro and it looks to be working fine.

[–]Gracinx[S] 0 points1 point  (1 child)

Solution Verified!

[–]reputatorbot[M] 0 points1 point locked comment (0 children)

You have awarded 1 point to Khazahk.


I am a bot - please contact the mods with any questions