index > Visual Basic for Applications (VBA) > Solved - Help with Excel VBA Code

Solved - Help with Excel VBA Code


I am trying to format different spreadsheets. I need the data to be in the same cells for each worksheet. This data is in column A. I need to check to see if DBCS# (?) is above Tour, and if so insert rows until Tour is in row 175, column A. The problem is that the number after DBCS# is never the same. How can I use an IF statement to make sure that the cell above Tour says DBCS# (whatever the number is)? This is the If statement that I tried. If I put DBCS#46 in my IF statement, it will not work because the number after # isn't always 46.

If (Range("A174:A174") = "DBCS#") And (Range("A175:A175") = "TOUR") Then
GoTo label_177:

Else:
Do While (Range("A174:A174") <> "DBCS#") And (Range("A175:A175") <> "TOUR")
Selection.EntireRow.Insert
Loop
End If


Example:

DBCS #33
Help Nikki
Hello, maybe this will help
Try
If (Left(Range("A174:A174") ,5)= "DBCS#") And (Range("A175:A175") = "TOUR") Then
GoTo label_177:
blackmamba
Thanks. I tried that and the program is still not working correctly.
Help TW
hmm,
Try Left(Cstr(Range...),5)
Also, is there a blank space between DBCS and # ? then you have to use left(string, 6).
blackmamba
I tried that also and it is still not working. There are no spaces between DBCS, #, and the number.
Help TW
Sorry, do you get a syntax error or the code loops infinitely ?
Cause i think the code after else is not the right one.
blackmamba
One more thing, use Cstr(Range(...)) to compare it with a string....
blackmamba
That worked. Thank you so very much.
Help TW

reply 8

You can use google to search for other answers

 

More Articles

• How to use Direct3D in VBA
• Getting New Textbox value without using Afterupdate
• How to copy pivot table RESULT from Access to Excel
• Undo Command(EXCEL)
• .Net Version in the future?
• Send Outlook message via VBA Macro in Excel
• How to handle CLOB Data in VBA for Excel?
• Copying email contents into Excel Spreadsheet via an Excel Macro
• Problem with XP SP2
• Variable for TextBox Objects
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

• Run-time error 13, "Type Mismatch&q
• partly remove the code from VBComponents
• VB Postgres connection problem
• Worksheet_Change Error
• 'Call was rejected by callee' using VBA
• Runtime error '13' - type mismatch probl
• How to read a URL?
• How to create a DLL in VB.net for MS Acc
• Adding a table column using VBA in Access
• combine 3 combo boxes values into one st
• Linking Outlook to Excel
• xlDialogPasteSpecial
• VBA resources
• 1004 - Application-Defined or Object-Def
• Is an Excel bug that set PivotItem.Visib

Hot Articles

• Retrieve IBM Workplace Forms data into E
• Help with DDEExecute
• dtpicker MicrosoftWord Template
• List Box Selection via Code (Access 2003)
• Put Certain E-mail Address in FROM Field
• Syntactical error within For loop (VBA e
• Argument syntax problem
• Save Each page of a Word merge as a sepe
• VBA6.4 sdk issues
• Collections Class For Each Next
• Accessing a subform, error 2455
• VBA Help File throws Internet Explorer S
• Detecting Excel Password
• Access 2003: Connect to Word Document.do
• How to create a hyperlink in Excel Chart.

Recommend Articles

• VBA WORKSHEET
• Optimise VBA for Multi-Processors
• Excel FTP using msinet.ocx - PROBLEM
• duplicate records with childs
• Personal.xls
• Return value from running a sql statement
• Custom Date Picker Control
• Suppress Linked View Unique Record Popup
• Activate a workbook based on a value in
• reportbuilder
• How to convert excel file to .DAT file?
• pass parameter to stored procedure
• Printing by using a vba code
• Writing To Text File Without Quotes
• Standard Difference Function