Macro vba code for moving row to ed automatically

SaraDeniston

New Member
Joined
Nov 22, 2018
Messages
1
I AM USING EXCELL 2019 and have reserached allot on macro codes/vba. I am trying to find a code that when excel opens every time, the rows that containe "Discharged" will automatically move to the bottom of the sheet and the ones that say "Inpatient" will stay at the top.
the column that contains Inpatient or discharged is J
as of right now I only have 30 rows but might have to add more if more patients are consulted
is there a way to do this

 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hello,

With a Workbook Open Event ... you can easily have a Sort macro which will produce your expected result ...

Two steps :

1. Create your Sort macro

2. Add the event macro to launch your Sort macro

Hope this will help
 
Upvote 0
.
The following presumes your patient data begins in Row 2, with Row 1 having column headers.


Paste the following in a module :


Code:
Option Explicit
Sub SortInptOutpt()
Dim lastrow As Long


lastrow = Cells(Rows.Count, 10)
Range("J2:J100").EntireRow.Sort key1:=Range("J2:J100"), _
   order1:=xlDescending, Header:=xlNo


End Sub

Paste the following in the module ThisWorkbook :

Code:
Option Explicit


Private Sub Workbook_Open()
    SortInptOutpt
End Sub
 
Upvote 0

Forum statistics

Threads
1,217,047
Messages
6,134,271
Members
449,862
Latest member
Muhamad Irfandi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top