Results 1 to 11 of 11
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365

    Excel Sheet

    Hi Guy's, is there any way i can stop the bold column going beyond the record quantity ?

    The column is currently going way beyond for example if there are 37 records, i would like the word "yes" to stop at 37, it currently starts at Cell 3,10 now goes down thousands of cells

    .Worksheets(1).Cells(2, 1) = "PLEASE REPLACE 'YES' "
    .Worksheets(1).Cells(3, 1) = "WITH 'N' IF ON HOLD"
    .Worksheets(1).Cells(1, 3) = "SHIPMENT DATE"
    .Worksheets(1).Cells(1, 4) = "DEL TO"
    .Worksheets(1).Cells(1, 5) = "SL NUMBER"
    .Worksheets(1).Cells(1, 6) = "PO-NUMBER"
    .Worksheets(1).Cells(1, 7) = "PRODUCT TYPE"
    .Worksheets(1).Cells(1, 8) = "PRODUCT DETAILS"
    .Worksheets(1).Cells(1, 9) = "STATUS"
    .Worksheets(1).Columns("J:J") = "Yes" continues way beyond the amount of records in recordset
    .Worksheets(1).Cells(1, 10) = "CAN SHIP YES"
    .Worksheets(1).Cells(2, 10) = ""
    .Worksheets(1).Cells(3, 3).CopyFromRecordset rs
    .Worksheets(1).Range("C3:K3").Borders(xlEdgeTop).L ineStyle = xlContinuous
    .Worksheets(1).Cells.EntireColumn.AutoFit
    .Worksheets(1).Cells.EntireColumn.HorizontalAlignm ent = xlLeft
    .Worksheets(1).Columns("C:C").NumberFormat = "dd-mmm-yy"


    .Worksheets(2).Cells(1, 3) = "SHIPMENT DATE"
    .Worksheets(2).Cells(1, 4) = "DEL TO"
    .Worksheets(2).Cells(1, 5) = "SL NUMBER"
    .Worksheets(2).Cells(1, 6) = "PO-NUMBER"
    .Worksheets(2).Cells(1, 7) = "PRODUCT TYPE"
    .Worksheets(2).Cells(1, 8) = "PRODUCT DETAILS"
    .Worksheets(2).Cells(1, 9) = "STATUS"
    .Worksheets(2).Cells(1, 10) = "RELEASED"
    .Worksheets(2).Cells(3, 3).CopyFromRecordset rsH
    .Worksheets(2).Range("C3:J3").Borders(xlEdgeTop).L ineStyle = xlContinuous
    .Worksheets(2).Cells.EntireColumn.AutoFit
    .Worksheets(2).Cells.EntireColumn.HorizontalAlignm ent = xlLeft
    .Worksheets(2).Columns("C:C").NumberFormat = "dd-mmm-yy"

  2. #2
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    .Columns("J:J") selects the whole column mate.

  3. #3
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    decide which column you are using to define the record count... EG column "A" will always have data if its a record. Then do a find last on column "A" for example and use this value in your VBA to decide where to stop.

    If that makes sense...

    https://www.excelcampus.com/vba/find...w-column-cell/

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Hi homegrownandy, thank you very much for your reply, i had a quick look and there may well be future requirements from your link, however, i tried thew following and it worked a treat for anyone else requiring similar

    .Worksheets(1).Range("J3:J" & rs.RecordCount) = "Yes"

  5. #5
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2016
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    you could also define the last row as a variable

    Code:
    Dim lr as long
    lr = .Worksheets(1).Range("J" & rows.count).end(xlup).row
    then

    for the row in question
    Code:
    .Worksheets(1).range("J3:J" & lr) ="Yes"

  6. #6
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Hi alansidman, thank you very much, will give that try tomorrow at work,

    Do I add the code in like below ?

    #
    .Worksheets(1).Cells(2, 1) = "PLEASE REPLACE 'YES' "
    .Worksheets(1).Cells(3, 1) = "WITH 'N' IF ON HOLD"
    .Worksheets(1).Cells(1, 3) = "SHIPMENT DATE"
    .Worksheets(1).Cells(1, 4) = "DEL TO"
    .Worksheets(1).Cells(1, 5) = "SL NUMBER"
    .Worksheets(1).Cells(1, 6) = "PO-NUMBER"
    .Worksheets(1).Cells(1, 7) = "PRODUCT TYPE"
    .Worksheets(1).Cells(1, 8) = "PRODUCT DETAILS"
    .Worksheets(1).Cells(1, 9) = "STATUS"
    lr = .Worksheets(1).Range("J" & rows.count).end(xlup).row DOES THIS NEED TO BE INSIDE THE WITH WORKBOOK STATEMENT ?
    .worksheets(1).Range("J3:J & lr) = "Yes"
    .Worksheets(1).Cells(1, 10) = "CAN SHIP YES"#

  7. #7
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Hi Guys, can I add more than 1 OrderBy ina Recordset ?

    And Status = '" & MyStatus & "'" & " And Source = '" & Src & "' ORDER BY DelTo;") Add another OrderBy ie: Date ??

    Kind Regards

  8. #8
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Hi alansidman, that method didnt appear to work, there was only one "yes" in J3 !!

    I did put the lr = .Worksheets(1).Range("J" & rows.count).end(xlup).row within the with workbook statement and following line was the code for row in question ??

    Kind Regards

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Yes, just as in a query object, sql built with code can have multiple sort criteria, separate with a comma. If you want descending order, specify with DESC keyword.

    Date is a reserved word and should not use reserved words as names for anything. If you do, enclose object names in [ ].

    & "' ORDER BY DelTo, [Date];")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Join Date
    Apr 2017
    Posts
    1,792
    1.Define your table as Table (Select a cell in table, from Menu select Insert>Table);
    2. Select whole data part of column in Table;
    3. Define Conditional Formatting for selected part of Table (NB! You have to use regular formula syntax in formula used to determine formatting condition - Conditional Formatting doesn't recognize Table syntax).

    When Table column contains a single formula or formatting rule for all data cells in column, then whenever rows are added into table, the formula or formatting rule are expanded automatically.

  11. #11
    Join Date
    Apr 2017
    Posts
    1,792
    1.Define your table as Table (Select a cell in table, from Menu select Insert>Table);
    2. Select whole data part of column in Table;
    3. Define Conditional Formatting for selected part of Table (NB! You have to use regular formula syntax in formula used to determine formatting condition - Conditional Formatting doesn't recognize Table syntax).

    When Table column contains a single formula or formatting rule for all data cells in column, then whenever rows are added into table, the formula or formatting rule are expanded automatically. And whenever something is entered into any cell immediately below last table cell, the Table is automatically expanded.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access Database from excel sheet
    By jambai in forum Import/Export Data
    Replies: 1
    Last Post: 11-26-2017, 04:00 AM
  2. Replies: 5
    Last Post: 04-25-2017, 01:38 AM
  3. act like excel sheet
    By moha1520 in forum Programming
    Replies: 3
    Last Post: 07-19-2016, 04:24 PM
  4. Replies: 26
    Last Post: 01-08-2013, 04:55 PM
  5. From Recordset to excel sheet
    By mark71 in forum Programming
    Replies: 1
    Last Post: 12-10-2012, 03:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums