Results 1 to 2 of 2

VBA variable declaration and assignment help

Threaded View

  1. #1
    Registered User
    Join Date
    02-06-2017
    Location
    California, US
    MS-Off Ver
    Office 2016
    Posts
    38

    VBA variable declaration and assignment help

    I am having trouble with the code in red. I would like to first search for the first empty cell in column C on Sheet1 then search on another sheet for a specific value to move over to the first empty cell in column C in sheet1.

    Option Explicit
    
    Sub Open_My_Files()
    Dim MyFile As String        ' File to be appeneded
    Dim MyPath As String        ' Pathname to where CSV files are kept
    Dim shS As Worksheet        ' Source worksheet
    Dim shD As Worksheet        ' Destination worksheet
    Dim lRow As Long
    Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
    Dim currentRowValue As String
    
    
    
    Application.DisplayAlerts = False
    
    ' Initialize Variable
    MyPath = "C:\\users\anthony777\desktop\"
    MyFile = Dir(MyPath & "\*.csv")
    
    
    ' Loop through files
    Do While MyFile <> ""
        ' Add a worksheet at the end of the current workbook and name it for the CSV fiel
        Worksheets.Add After:=Sheets(Sheets.Count)
        Set shD = Sheets(Sheets.Count)
        shD.Name = Replace(MyFile, ".csv", "")
        
        ' Open the CSV file
        Workbooks.Open MyPath & "\" & MyFile
        ' We can "get away with the following because we know the CSV file is active since we just opened it.
        ' We also know that CSV files only have one sheet
        Set shS = ActiveWorkbook.Sheets(1)
        
    
       
        ' Copy all on this sheet
        shS.Cells.Copy
        
        ' close the workbook
        ActiveWorkbook.Close savechanges:=False
        
        ' The book knows that shD is part of it.
        shD.Range("A1").PasteSpecial xlAll
        'activate correct sheet
        
        Worksheets("Inspection Data Sheet").Activate
        'find the first blank cell in column c
        sourceCol = 3
        rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row
        currentRowValue = Cells(currentRow, sourceCol).Value
            If IsEmpty(currentRowValue) Or currentRowValue = "" Then
                Cells(currentRow, sourceCol).Select
    
            shS.Range("A1").Select
            Cells.Find(What:="axis", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
                :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
                False, SearchFormat:=False).Activate
            ActiveCell.Offset(1, 0).Select
            End If
            
            If ActiveCell = "TP" Then
                ActiveCell.Offset(0, 3).Select
            End If
            
            
    
    
       
        ' Get the next file
        MyFile = Dir()
    Loop
    Application.DisplayAlerts = True
    
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Meaning of characters in %, !, $ and # in variable declaration
    By Plotseling in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2013, 04:59 AM
  2. [SOLVED] Conditional public variable declaration
    By RedWing in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-13-2012, 11:16 AM
  3. [SOLVED] Variable Declaration issue
    By NewToCode in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2012, 01:57 PM
  4. passing a variable to an array declaration
    By labogola in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-09-2012, 04:10 AM
  5. Range Declaration using Variable
    By wfire in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-11-2009, 11:43 AM
  6. Changing variable value without explicit declaration
    By carg1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-05-2007, 02:42 PM
  7. A disturbing behaviour of DIM (for variable declaration)
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-11-2005, 01:20 PM
  8. Declaration of public variable - Question
    By Les Stout in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-05-2005, 10:05 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1