+ Reply to Thread
Results 1 to 7 of 7

store all the values of cells which are in range

  1. #1
    Forum Contributor
    Join Date
    05-30-2013
    Location
    Isreal
    MS-Off Ver
    Excel 2010
    Posts
    191

    store all the values of cells which are in range

    I have two questions:
    1.I would like to store all the values of cells which are in range(Arr_photo)
    Please help me out with the following code.
    Please Login or Register  to view this content.
    Sub photo()
    Dim last_row As Integer
    Dim lastCol As Integer
    Dim Arr_photo As Variant
    Dim ws As Worksheet
    Dim ws2 As Worksheet
    Dim wkb As Excel.Workbook
    Set wkb = ThisWorkbook
    Set ws = Sheets("photo")
    wkb.Sheets("photo").Select
    last_row = ws.UsedRange.Rows.Count
    lastCol = ws.UsedRange.Columns.Count
    Arr_photo = Cells(last_row, lastCol).Value

    End Sub

    Please Login or Register  to view this content.

    2.I have samples spreadsheet attached to this post named sample one.
    The samples spreadsheet has 2 sheets "main" and "photo"
    On cells b2 and b3 in the "photo" spreadsheet there is an Excel equation with a vlookup I would like to drag down the equations to fill in the information for sku's 2 and 3 the dragging needs to be similar to the way I would have occurred if I would have marked on my Excel b2 and b2 in the "photo" spreadsheet and move my mouse down.
    Any ideas how this can be done?

    Thank you for your help
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: store all the values of cells which are in range

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    05-30-2013
    Location
    Isreal
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: store all the values of cells which are in range

    Hello.
    Thank you for your response.

    However there are two things which I don’t understand.
    1. You gave the following answer
    Please Login or Register  to view this content.
    Arr_photo = Sheets("photo").UsedRange.Value.
    Please Login or Register  to view this content.
    However the issue I have with this answer let say I do not want to store all the information in the spreadsheet only certain information let say form c3:h3 also I would like to make the information I decide to store be flexible therefore in my original code I used Arr_photo = Cells(last_row, lastCol).Value. Please advise.

    2.For the following sub

    Please Login or Register  to view this content.
    Range("B2:C2").AutoFill Destination:=.Range("B2:C" & .Range("A" & Rows.Count).End(xlUp).Row).
    Please Login or Register  to view this content.
    Can you explain how Destination:=.Range("B2:C" & .Range("A" & Rows.Count).End(xlUp).Row) works I was not able to understand.

    Thanks agin.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: store all the values of cells which are in range

    Quote Originally Posted by starlev View Post
    1. only certain information let say form c3:h3 also I would like to make the information I decide to store be flexible therefore in my original code I used Arr_photo = Cells(last_row, lastCol).Value.
    You haven't explained what criteria determines C3:H3 or what range you want? How do you decide what to store? Do you just want to store the selected cells?

    Cells(last_row, lastCol)
    This is just the last used cell on the sheet.

    Quote Originally Posted by starlev View Post

    Can you explain how Destination:=.Range("B2:C" & .Range("A" & Rows.Count).End(xlUp).Row) works
    .Range("A" & Rows.Count).End(xlUp).Row
    This returns the row number of the last used row in column A
    In your example workbook, that was row 4

    .Range("B2:C" & (Last used row)
    This defines the Range B2:C4

  5. #5
    Forum Contributor
    Join Date
    05-30-2013
    Location
    Isreal
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: store all the values of cells which are in range

    Thank you again for your help.
    For question one I would like to store all the values in the work sheet in a Variant starting from a2 until the last value in the spreadsheet and the Variant to paste into a new workbook.

    Question two got it thanks again for your help.

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: store all the values of cells which are in range

    Quote Originally Posted by starlev View Post
    Thank you again for your help.e to store all the values in the work sheet in a Variant starting from a2 until the last value in the spreadsheet and the Variant to paste into a new workbook.
    I'm confused. That's quite a bit different than C3:H3.
    It's very much what I had originally suggested except for the first row.

    This copies the used range offset by one row. So row 1 is not copied.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    05-30-2013
    Location
    Isreal
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: store all the values of cells which are in range

    And how would I paste?
    I was trying to paste with
    Please Login or Register  to view this content.
    Workbooks.Add
    Range("a2").Select
    Arr_photo.PasteSpecial _
    Operation:=xlPasteSpecialOperationAdd
    Please Login or Register  to view this content.
    However it did not work

+ 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. Store range of cells in another worksheet and assign ID to row
    By cajand in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-21-2014, 07:33 AM
  2. Replies: 4
    Last Post: 06-18-2014, 12:19 PM
  3. Store and retreive values of selected cells
    By lovallee in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-16-2014, 06:59 PM
  4. [SOLVED] Store consecutive cells range
    By fgq in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-14-2013, 09:51 AM
  5. Referring to range and store values
    By Ranjani in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-27-2009, 05:01 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