+ Reply to Thread
Results 1 to 9 of 9

VBA query with keeping column

  1. #1
    Forum Contributor
    Join Date
    03-23-2011
    Location
    Ormesby
    MS-Off Ver
    Microsoft 365 MSO
    Posts
    130

    VBA query with keeping column

    Everyone hello,

    I have a query, where I want to keep a certain column (eg BB) but I have an existing vba that deletes all rows from 6:1000;

    This is the vba I have that removes the rows:

    Private Sub Run_Code_Click ()
    If ActiveSheet.Cells (1, 2) = "" Then exit Sub
    'Clear Data Sheet

    ActiveSheet. Rows ("6:1000"). ClearContents
    ActiveSheet. Rows ("6:1000"). ClearFormats
    ActiveSheet. Rows ("6:1000"). Validation.Delete
    ActiveWindow.FreezePanes = False
    Application.ScreenUpdating = False
    Application.EnableEvents = False

    What I would like, is for Column BB not to be removed.
    how do I add that to the code as BB has data that is needed and I have to manually add each time the file updates.

    I hope you will be able to help.

    Many thanks

    Pugg

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,913

    Re: VBA query with keeping column

    You could do something like...
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Contributor
    Join Date
    03-23-2011
    Location
    Ormesby
    MS-Off Ver
    Microsoft 365 MSO
    Posts
    130

    Re: VBA query with keeping column

    Do I replace the data with the current data I gave you and do I remove all:
    Private Sub Run_Code_Click ()
    If ActiveSheet.Cells (1, 2) = "" Then exit Sub
    'Clear Data Sheet

    ActiveSheet. Rows ("6:1000"). ClearContents
    ActiveSheet. Rows ("6:1000"). ClearFormats
    ActiveSheet. Rows ("6:1000"). Validation.Delete
    ActiveWindow.FreezePanes = False
    Application.ScreenUpdating = False
    Application.EnableEvents = False

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,913

    Re: VBA query with keeping column

    Please use # button (code tag) to nest your code in block.

    You replace part of your code, like...
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    03-23-2011
    Location
    Ormesby
    MS-Off Ver
    Microsoft 365 MSO
    Posts
    130

    Re: VBA query with keeping column

    Ok thx, that works but there is an issue where all the data from BB disappears when i click on the update button
    Any reason why that is happening.

    I ran it 3 times and the same thing happens

    Pugg

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,913

    Re: VBA query with keeping column

    No idea without looking at your entire code and/or sample workbook that replicates your issue.

  7. #7
    Forum Contributor
    Join Date
    03-23-2011
    Location
    Ormesby
    MS-Off Ver
    Microsoft 365 MSO
    Posts
    130

    Re: VBA query with keeping column

    How do I change the following, as it may have something to do with it:

    I have this added code:

    Dim mystring As String
    Dim RowCount As Long
    RowCount = WorksheetFunction.CountA(Range("AD:AD"))
    For i = 2 To RowCount
    myString = Trim(Cells)i, 9).Value)
    If InSrt(myString, "25") > 0 Then
    Cells(i, 30).Value = Cells(i, 54).Value
    End If
    Next
    End Sub


    The Cells (i, 54) is Column BB
    The data in column BB is added to Cell(i, 30) to give time.

    Can I replace the Cells so they look up a range in another sheet, as Column BB when ran removes data

    Pugg

  8. #8
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,913

    Re: VBA query with keeping column

    Without sample workbook, bit hard to help you.

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,939

    Re: VBA query with keeping column

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

+ 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. Replies: 1
    Last Post: 09-16-2019, 12:57 PM
  2. Power Query - removing duplicate data, but keeping second set?
    By IronCladRooster in forum Excel General
    Replies: 0
    Last Post: 10-18-2018, 07:24 PM
  3. [SOLVED] powery query issue keeping leading zeros
    By JEAN1972 in forum Excel General
    Replies: 2
    Last Post: 11-25-2017, 01:38 AM
  4. Unpivot in Power Query keeping two columns
    By PennyK in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 05-10-2017, 06:27 AM
  5. [SOLVED] access query design help - adding field while keeping all records
    By darpodo in forum Access Tables & Databases
    Replies: 9
    Last Post: 05-11-2016, 08:37 AM
  6. [SOLVED] Removing duplicates from column A while keeping their respective values from column B
    By joel.mugabe in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-19-2016, 02:38 AM
  7. Replies: 3
    Last Post: 04-28-2014, 02:24 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