The online racing simulator
Excel Macro VBA Headache
(1 post, started )
Excel Macro VBA Headache
A simple one for the clever people of the LFS forum.

I have an excel 'program', and it works like I want it to. Am refining my save/load functions within the program (it basically saves to another sheet), and am making Excel write the values to the first empty cell it finds - all cells will be populated, so shouldn't prove a problem at the moment, but I know it's not ideal.

Anyway, here is the start of my vba code (all of which I've pinched from elsewhere, none of it is my own work as such).

What I'd like to do is for it to write a new line if the data is new, but overwrite existing lines if the data is already there.

Current code:
Sub Save()

Application.ScreenUpdating = False
Dim Cell As Range
Set Cell = ActiveCell

Sheets("Main").Select
Range("SetupName").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Database").Select
Range("A3").Select
While ActiveCell.Value <> ""
ActiveCell.Offset(1, 0).Select
Wend
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Sheets("Main").Select
Range("CarType").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Database").Select
Range("B3").Select
While ActiveCell.Value <> ""
ActiveCell.Offset(1, 0).Select
Wend
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Sheets("Main").Select
Range("frrh_desired").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Database").Select
Range("C3").Select
While ActiveCell.Value <> ""
ActiveCell.Offset(1, 0).Select
Wend
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Sheets("Main").Select
Range("rrrh_desired").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Database").Select
Range("D3").Select
While ActiveCell.Value <> ""
ActiveCell.Offset(1, 0).Select
Wend
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False


and so on...

If SetupName AND CarType match an existing row, then save all the values to that row, otherwise save to the new row as it is. But I can't work out how to make it check properly. I just get errors.

Over to you. Excel 2007 if it makes any difference. Don't mock for simplicity of code or stupidity of problem. Thanks!

Excel Macro VBA Headache
(1 post, started )
FGED GREDG RDFGDR GSFDG