Results 1 to 4 of 4

If Condition is True, Save Data in Array, and Copy Array Data to other Worksheet

Threaded View

skelly8117 If Condition is True, Save... 08-30-2013, 01:26 PM
Leith Ross Re: If Condition is True,... 08-30-2013, 02:34 PM
skelly8117 Re: If Condition is True,... 09-06-2013, 09:07 AM
skelly8117 Re: If Condition is True,... 09-10-2013, 10:18 AM
  1. #1
    Registered User
    Join Date
    05-22-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    6

    Talking If Condition is True, Save Data in Array, and Copy Array Data to other Worksheet

    Hello-

    I am new to writing Excel VBA. My goal is to start with a specific worksheet called "Hoist1", evaluate Column I called "Safety Code" beginning on row 7, and compile records with 2s and 3s (exclude the 1s). I need to save the values (all text data type) found in Columns B, A, and J in this order, to an array.

    After evaluating all rows, I need to proceed to the next worksheet and do the same. There are a total of 8 consecutive worksheets.

    Lastly, I need to copy the data saved in the array to the Summary worksheet into its columns A, B, and C beginning on row 7. Initially, there are two blank rows. Therefore, after the two rows have been filled, I need the VBA procedure to insert a new row after the second row.

    By the way, there is a column called "Action Code" in Column J for which I need to copy data from the same eight worksheets to the Summary worksheet beginning 4 rows after the last Safety Code.

    Please let me know if you have any questions or need any clarifications.

    Thank you for your patience as I am a "newbie!"

    Skelly
    Option Explicit     
    ‘The “Add” btn to be clicked after all component worksheets have been completed.
    Sub UpdateLogWorksheet()   ‘The “Add” btn
        Dim Compilation As Worksheet  ‘Summary Tab
        Dim wks As Worksheet  ‘The Active Worksheet
        Dim iCounter As Integer
        Dim xRow As Long    
        Dim Safety23array() As Variant
        Dim issueCounter As Integer
        Dim oCol As Long
        
        Set xRow = 7    
        Set wks = Worksheets("Hoist1")   ‘Active worksheet (One of the 8 Worksheets are named Hoist1 through Runway)
        Set Compilation = Worksheets("Summary")
        oCol = 1 'order info is pasted on data sheet, starting in this column
      Set myCopy = Safety23.Range("SafetyCodeCol")   ‘SafetyCodeCol-a Name Range for Column I’s Safety Codes 1, 2 or 3
    	
    ‘***
    ‘***Compiling Safety Codes information from three columns where the Safety Code equals either 2 or 3.
    ‘***‘See p.106 looping through worksheets
    ‘***
    iCounter = 1
    issueCounter =0
    Do While  iCounter <=8  ‘loop once for each of the eight worksheets beginning with Hoist1
    	
    	If Range (“I” & xRow).Value = “2” or Range (“I” & xRow).Value = “3” Then
    
    			ReDim Preserve Safety23array(issueCounter)
    			Safety23array(issueCounter) =   ???   Store as 3 part string in element.  Save cells b, a and j values in this order.
    		
    			 issueCounter = issueCounter +1
    		Next xRow	
    		End If
    iCounter = iCounter + 1
    Loop		‘Do While Loop
    
    ‘**** Paste into Summary Tab
    issueCounter = 0     
    For issueCounter = LBound(Safety23array) To UBound(Safety23array)  ‘The number of Safety Code issues is dynamic.
    	With compilation
    		If issueCounter > 1 Then  ‘The Summary initially has only two blank rows under Safety Code.
    			Rows(xRow).Insert  ‘After adding two Safety Codes valued at 2/3, add a new row in the Summary wks.
    			Safety23array(issueCounter).Copy  'copy the Safety Code data and paste onto data sheet
    			.Cells(nextRow, oCol).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    		Else
    			Safety23array(issueCounter).Copy  'copy the Safety Code data and paste onto data sheet
    			.Cells(nextRow, oCol).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    
    		Application.CutCopyMode = False
    	End With
    Next issueCounter
    Last edited by Leith Ross; 08-30-2013 at 02:31 PM. Reason: Added Code tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Quick Array question - Copy array to another array then resize?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-02-2013, 01:17 AM
  2. Using an Array to Copy Data to a Worksheet
    By Cofad in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-04-2013, 09:19 PM
  3. Copy worksheet and data from array
    By swaboe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2013, 06:45 AM
  4. Using array to transfer data of different data types to worksheet
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-13-2011, 03:12 PM
  5. Copy data from one cell to another if a blank condition is true
    By gadjit in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-08-2009, 08:17 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