0

I have a simple question that should be simple to answer. I am trying to make a string reflect the value of a cell. The naming scheme of the spreadsheet that it will import is the value of "(CSV) & ("[1].csv") with no space. CSV is the value of B5. If the variable CSV = WASHINGTON I need the line to read

Windows(WASHINGTON[1].csv).Activate

Below is what I have. I am having an error with the CSV Variable.

Sub Import_CSV()

Import_CSV Macro

    Dim CSV As Long
    Application.DisplayAlerts = False
    Windows("Records.xlsm").Activate
    Worksheets("Data").Activate
    CSV = Cells(5, "B").Value
    Windows(CSV & "[1].csv").Activate
    Rows("1:2").Select
    Range("A2").Activate
    Selection.Cut ... etc

Any Help is greatly appreciated.

3
  • 1
    What is my error? WHy don't you tell us what the error is, and then perhaps we can tell you how to fix it. Commented Jun 13, 2014 at 17:39
  • 2
    You have declared CSV As Long but you are expecting a String data type. That will almost certainly raise a mismatch error for any non-numeric value. Commented Jun 13, 2014 at 17:39
  • Very true. I did not phrase that good at all. I apologize for that. Found a site that answered my question : dummies.com/how-to/content/vba-for-dummies-cheat-sheet.html Commented Jun 13, 2014 at 18:13

1 Answer 1

2

You have declared CSV As Long but you are expecting a String data type. That will almost certainly raise a mismatch error for any non-numeric value.

Declare Dim CSV as String and that should resolve it.

Note: This assumes that the specified file is already open. If not, you will get an error on the .Activate statement.

You should also avoid using Activate and Select methods. There are some resources on here that explain why:

How to avoid using Select in Excel VBA macros

Please, in the future do a better job describing what your actual problem is -- if you get an eerror message, indicate what that message is, and on which line it raises. This is very helpful for others who are trying to assist you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.