+ Reply to Thread
Results 1 to 5 of 5

vba to copy every singe cell using WITH

Hybrid View

Muktar888 vba to copy every singe cell... 05-09-2017, 11:49 AM
Richard Buttrey Re: vba to copy every singe... 05-09-2017, 11:59 AM
Muktar888 Re: vba to copy every singe... 05-15-2017, 05:20 PM
Norie Re: vba to copy every singe... 05-15-2017, 05:34 PM
JOHN H. DAVIS Re: vba to copy every singe... 05-16-2017, 07:30 AM
  1. #1
    Registered User
    Join Date
    04-30-2017
    Location
    Pretoria, South Africa
    MS-Off Ver
    2013
    Posts
    54

    vba to copy every singe cell using WITH

    Hey guys,

    I adapted this code, I am trying to copy every single cell as is for the stipulated column, but it only copies rows in that column where there is a rank in column A. You can run my macro to see the copy over issue.

    attached is my code and excel.
    the 3rd tab shows what it should look like when copying columns A and C into dws from sws column A & B. if you make this work, il adapt it for the rest of the columns.

    It also needs to paste in the Funds sheet from row 3, not row 2.

    
    Sub fundscopyover()
    
    Dim WIP As Worksheet, Funds As Worksheet
    
    Dim sws As Worksheet, dws As Worksheet
    Dim slr As Long, dlr As Long, r As Long
    Dim sRng As Range, sCell As Range
    
    With Application
        .Calculation = xlCalculationManual
        .EnableEvents = False
        .ScreenUpdating = False
    End With
    
    Set sws = Sheets("WIP")
    Set dws = Sheets("Funds")
    slr = sws.UsedRange.Rows.Count
    
    sws.AutoFilterMode = False
    With sws
            Set sRng = sws.Range("B3:B" & slr)
            For Each sCell In sRng
                r = sCell.Row
                dlr = dws.Cells(Rows.Count, 1).End(xlUp).Row + 1
                dws.Range("A" & dlr).Value = sws.Range("A" & r).Value
                dws.Range("B" & dlr).Value = sws.Range("BB" & r).Value
                dws.Range("C" & dlr).Value = sws.Range("B" & r).Value
                dws.Range("D" & dlr).Value = sws.Range("I" & r).Value
                dws.Range("G" & dlr).Value = sws.Range("F" & r).Value
                dws.Range("H" & dlr).Value = sws.Range("G" & r).Value
                dws.Range("I" & dlr).Value = sws.Range("H" & r).Value
                dws.Range("J" & dlr).Value = sws.Range("M" & r).Value
                dws.Range("L" & dlr).Value = sws.Range("Q" & r).Value
                dws.Range("M" & dlr).Value = sws.Range("U" & r).Value
                dws.Range("N" & dlr).Value = sws.Range("Y" & r).Value
                dws.Range("O" & dlr).Value = sws.Range("AC" & r).Value
                dws.Range("P" & dlr).Value = sws.Range("AG" & r).Value
                dws.Range("Q" & dlr).Value = sws.Range("AK" & r).Value
                dws.Range("R" & dlr).Value = sws.Range("AZ" & r).Value
                dws.Range("S" & dlr).Value = sws.Range("AT" & r).Value
                dws.Range("T" & dlr).Value = sws.Range("AU" & r).Value
                dws.Range("U" & dlr).Value = sws.Range("AO" & r).Value
                dws.Range("V" & dlr).Value = sws.Range("AP" & r).Value
                dws.Range("W" & dlr).Value = sws.Range("AR" & r).Value
                dws.Range("X" & dlr).Value = sws.Range("AV" & r).Value
                dws.Range("Y" & dlr).Value = sws.Range("AW" & r).Value
                dws.Range("Z" & dlr).Value = sws.Range("AX" & r).Value
                dws.Range("AA" & dlr).Value = sws.Range("AN" & r).Value
                dws.Range("AB" & dlr).Value = sws.Range("D" & r).Value
            Next sCell
        
    End With
    
    
    With Application
        .Calculation = xlCalculationAutomatic
        .EnableEvents = True
        .ScreenUpdating = True
    End With
    
    
    End Sub
    Thanks guys
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: vba to copy every singe cell using WITH

    Surely all you neeed is:

    Sub CopyFunds()
       Sheet2.Range("A1").CurrentRegion.Offset(2, 0).Resize(, 2).Copy Sheet13.Range("A3")
    End Sub
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    04-30-2017
    Location
    Pretoria, South Africa
    MS-Off Ver
    2013
    Posts
    54

    Re: vba to copy every singe cell using WITH

    Quote Originally Posted by Richard Buttrey View Post
    Surely all you neeed is:

    Sub CopyFunds()
       Sheet2.Range("A1").CurrentRegion.Offset(2, 0).Resize(, 2).Copy Sheet13.Range("A3")
    End Sub
    Hey Richard

    I tried this but i see that it copies column A & B, this is fine.

    But il need to copy specific single columns that are not next to each other.

    I will try this and let you know the outcome.

    Sorry been busy, but still need this.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: vba to copy every singe cell using WITH

    Why are you copying individual cells?

    Couldn't you use something like this without looping?
    sws.Range("A3:A" & slr).Copy
    
    dws.Range("A" & dlr).PasteSpecial xlPasteValues
    
    sws.Range("B3:B" & slr).Copy
    
    dws.Range("B" & dlr).PasteSpecial xlPasteValues
    If posting code please use code tags, see here.

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: vba to copy every singe cell using WITH

    Does this help?

    Sub Muktar888z()
    Dim x As Long, ws As Worksheet
    With Application
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
    End With
    Set ws = Sheets("WIP")
    With ws
        x = .Range("B" & Rows.Count).End(3).row
            .Range("A3:A" & x).Copy Sheets("Funds").Range("A3")
            .Range("B3:B" & x).Copy Sheets("Funds").Range("C3")
    End With
    With Application
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Combine Multiple Worksheet Change Events in a Singe Woksheet
    By Kimston in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-21-2015, 11:48 AM
  2. Conditional formatting in multiple cell based on a singe cell
    By Macster in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2014, 04:12 AM
  3. [SOLVED] Sorting singe row and column data into row and multiple colums
    By dhbyrne in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-24-2014, 04:56 AM
  4. Condensing a list into singe entries for an overview.
    By JSallen in forum Excel General
    Replies: 3
    Last Post: 11-30-2012, 06:40 PM
  5. Copy Pictures from separate sheets to one singe sheet.
    By Fishwise in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-17-2009, 03:03 PM
  6. How to add a singe symbol to the whole column data?
    By usmleboy in forum Excel General
    Replies: 3
    Last Post: 01-07-2006, 04:10 AM
  7. [SOLVED] How can you identify duplicate entries in a singe column?
    By Melissa in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-04-2006, 05:25 PM

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