Microsoft Access VBA to delete null rows? - vba

I'm looking to build a VBA to delete the entire row of a table in access if a certain column is empty, lets call the column "services". This would have run on a loop so anytime data was added it would check, if possible. I am using an auto-generated ID in a different column if that changes anything. Thanks in advance

When importing the data into access from excel, modify your query to not pull any information when that cell is null.
If you are not using a query and just a range selection, I would loop through each row looking for the null value, if it is not null then copy the row to another sheet inside the excel workbook and export that worksheet once the loop is finished.
( I would have commented but do not have enough rep )

Related

Index Match or Vlookup in a Power Query

I am trying to build a query that populates data in a column in a similar way to how an index, match or vlookup works.
My workbook has 2 sheets:
Contains open order data pulled from SQL (SQL_Data)
Contains saved comments that were manually entered on the SQL sheet (Preserved_Comments)
I have two queries set up:
Saves the order number and the manually input comments from the SQL_Data sheet, and puts them in a table on the Preserved_Comments Sheet
Refreshes the SQL data table
I have been trying to add a 3rd query that adds the comment column back into the SQL_Data sheet, but I can't figure out how to do a join / index, match / Vlookup that looks at the order numbers and populates the saved comment.
My goal for this is to create an order report where when the SQL data is refreshed, the manually added comments are saved and follow the order number.
Any guidance would be appreciated!
You can merge both Queries into a new one. Use a key column, It would be the lookup array in INDEX/MATCH. This should allow you to join the column.

Update Script to Populate empty fields

I have empty cells in a sql table that I would like to populate at one time. I have an excel spreadsheet with the corresponding numbers that need to go in the empty cells. I would like to take the spreadsheet and use it to populate the empty cells in ssms.
Excel Spreadsheet
Based on what I've read I need to make an update script that will take the spreadsheet and say, "where you find a matching OBJECTID update the number from STAND_OPER_CODE(spreadsheet) to the STAND_OPER_CODE(SSMS)"
SSMS

How to copy selected columns and filter them before hand in excel VBA

I am just a beginner in VBA. I am trying to copy some data from one workbook that is updated daily to a master woorkbook and generate a report. I want it to first filter one of the columns for nonzero values and copy it with three selected columns for example columns T,C,N. I have looked everywhere for an answer but I haven't succeeded yet. Please help.
You can check if a given cell has value 0 by something like this If Sheets(sheetname).Cells(rownumber,columnnumber)=0 Then
You haven't specified what do you want to do on the other workbooks with the cells that were empty.

Duplicated cells skip 10 rows

I have an Excel spreadsheet with two sheets, Sheet 1 contains some text and formulas I wish to duplicate down to write 2,000 odd lines of C# code for my project. Extremely repetitive, so I thought I could use Excel to write it for me. Sheet 2 contains an extract from my database which I wish to use to populate that values with. My section of Excel code looks like this and is spread out over 10 rows and 5 columns:
new AccountingPeriod()
{
MonthCovered="=Sheet2!B2",
StartDate=DateTime.Parse("Sheet2!C2"),
EndDate=DateTime.Parse("Sheet2!D2"),
AccountingPeriodDescription="Sheet2!E2",
Active='=Sheet2!F2',
April='=Sheet2!G2,
TaxYear="Sheet2!H2"
},
When I highlight these 10 rows and use the Excel duplicate tool I want the cell references (for example, in my spreadsheet Sheet1!D3 = Sheet2!B2, I want Sheet1!D13 = Sheet2!B3 NOT Sheet2!B13) to increment by 1, not 10 as it's doing in my spreadsheet.
We have tried an alternative solution of writing a macro to insert 10 blank rows in Sheet2 for every populated row so that the duplicated references are correct in Sheet1 but we're currently failing miserably at getting that to work correctly.
Instead of a direct reference that is going to change on a 1-to-1 with the copy, use the INDEX function with a little maths to achieve the 10-to-1 row stagger.
In Sheet1!D3 this references Sheet2!B2.
=INDEX(Sheet2!B:B,INT(ROW(1:1)/10)+2)
In Sheet1!D13 this references Sheet2!B3.
The OFFSET function can accomplish the same thing but it is a volatile function that recalculates whenever anything in the workbook changes. INDEX provides the same functionality while remaining non-volatile and will only recalculate when something that affects its returned value changes.

SQL query in excel returning one value uses two rows or columns?

I'm running a query from excel to sql server that returns a single value. It seems as if this uses two cells in excel. Is this correct? Is there a way to prevent this? Is there a way to predict whether excel will use an extra row or an extra column (I've seen both happening)?
If, in excel, I use "import external data -> new database query", and then do a count() on an sql server table, excel usually puts the result in the cell underneath the cell which I had selected when starting to do the new query (not adding an extra row, but putting the value there). Sometimes, it will instead insert an extra column before the column of the cell I had selected and put the result in the new column in the same row as the cell I had selected.
Is there a way to have excel return the value in the same cell as the one selected when starting the query? If not, is there a way to predict which of the two scenarios above will happen?
Thanks,
Ernst
I finally found the answer:
uncheck preserve column sort/filter/layout